package org.apollo.sqlite.sql.sub;


import java.util.Arrays;
import org.apollo.sqlite.core.SqliteContext;


public class SqlGroupBy implements GroupBy {
	
	private StringBuilder sqlBuilder;

	public SqlGroupBy(StringBuilder sqlBuilder) {
		this.sqlBuilder = sqlBuilder;
	}

	@Override
	public GroupByConst groupBy(String... args) {
		return groupBy(Arrays.asList(args));
	}

	@Override
	public GroupByConst groupBy(Iterable<String> args) {
		sqlBuilder.append(" GROUP BY");
		for (String arg : args) {
			sqlBuilder.append(" " + SqliteContext.getColumn(arg)).append(",");
		}
		sqlBuilder.delete(sqlBuilder.length() - 1, sqlBuilder.length());
		return new SqlGroupByConst(sqlBuilder);
	}

}
